<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ ondone }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          @click="$emit('setActive', 'all')"
          :class="{ selected: isActive === 'all' }"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          @click="$emit('setActive', 'ondone')"
          :class="{ selected: isActive === 'ondone' }"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          @click="$emit('setActive', 'done')"
          :class="{ selected: isActive === 'done' }"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clearDone">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: ["arr", "isActive"],
  computed: {
    ondone() {
      return this.arr.filter((item) => !item.isDone).length;
    },
  },
  methods: {
    clearDone() {
      const undone = this.arr.filter((item) => !item.isDone);
      this.$emit("onClear", undone);
    },
  },
};
</script>
